function checkInput(e) {

    var username = document.querySelector('input[type="text"]');
    var password = document.querySelector('input[type="password"]');
    var flag = 0;
    var pass = document.getElementById('password');
    var username = document.getElementById('username');


    if (pass.disabled == true || username.disabled == true) {

        return true;

    }

    if (username.value.length == 0) {

        username.nextElementSibling.style.display = 'inline'
        e.preventDefault();
        flag = 1;

    } else {

        username.nextElementSibling.style.display = 'none'

    }

    if (password.value.length == 0) {

        password.nextElementSibling.style.display = 'inline'
        e.preventDefault();
        flag = 1;


    } else {

        password.nextElementSibling.style.display = 'none'

    }

    if (flag = 1) {

        return false;
    };

    return true;

}

function disableLogin(e) {

    var pass = document.getElementById('password');
    var username = document.getElementById('username')

    if (e.target == null && e.checked == true) {


        disabled(pass, username)
        return;
    } else if (e.target == null) {

        return
    };


    if (e.target.checked == true) {

        disabled(pass, username)

    } else {

        pass.disabled = false;
        pass.previousElementSibling.style.color = "#000000"

        username.disabled = false;
        username.previousElementSibling.style.color = "#000000"

    }

}

function disabled(pass, username) {

    pass.disabled = true;
    pass.previousElementSibling.style.color = "#C9C4BC"
    pass.value = "";

    username.disabled = true;
    username.value = "";
    username.previousElementSibling.style.color = "#C9C4BC"


    var stars = document.querySelectorAll(".star");
    for (var i = 0; i < stars.length; i++) {

        stars[i].style.display = 'none';

    };
}


function addEvent(evnt, elem, func) {
    if (elem.addEventListener) { // W3C DOM
        elem.addEventListener(evnt, func, false);
    } else if (elem.attachEvent) { // IE DOM
        elem.attachEvent("on" + evnt, func);
    } else { // No much to do
        elem[evnt] = func;
    }
}

function attachEvents() {

    var login = document.querySelector('button');
    var checkBox = document.getElementById('windowsAuthentication')

    addEvent('click', login, checkInput);
    addEvent('click', checkBox, disableLogin);

}

window.onload = function() {

    var checkBox = document.getElementById('windowsAuthentication')
    disableLogin(checkBox);

    attachEvents()

}